<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\controller;

use app\common\model\GamblerKing;
use app\common\model\GamblerKingInvestmentUser;

/**
 * Action控制器
 */
class KingAction extends AdminBase
{
    
    /**
     * Action列表
     */
    public function ActionList()
    {
        
        $where = $this->logicAction->getWhere($this->param);
        
        $this->assign('list', $this->logicAction->getActionList($where, 'a.*,k.name as king_name', 'a.create_time desc'));
        $this->assign('param',$this->param);
        return $this->fetch('action_list');
    }
    
    /**
     * Action添加
     */
    public function ActionAdd()
    {
        if(isset($_POST['king'])){
            $list=GamblerKingInvestmentUser::alias('a')->field('a.*,i.name')->join('__GAMBLER_KING_INVESTMENT__ i','a.investment_id=i.id')->where(['a.state'=>1,'a.king_id'=>$_POST['king_id']])->select();
            return $list;
        }
        $this->ActionCommon();
        $this->assign('type',$this->param['type']);
        $this->assign('king_list',GamblerKing::alias('a')->field('a.*')->join('__MEMBER__ m','a.user_id=m.id')->where(['is_company'=>1])->select());
        switch ($this->param['type']){
            case 1:
            case 2:
            case 4:
                return $this->fetch('user_action_edit');
                break;
            case 3:
                return $this->fetch('user_action_edit1');
                break;

        }

    }
    
    /**
     * Action编辑
     */
    public function ActionEdit()
    {
        
        $this->ActionCommon();
        
        $info = $this->logicAction->getActionInfo(['a.id' => $this->param['id']], 'a.*');

        
        $this->assign('info', $info);
        $this->assign('type', $info['type']);
        $this->assign('king_list',GamblerKing::alias('a')->field('a.*')->join('__MEMBER__ m','a.user_id=m.id')->where(['is_company'=>1])->select());
        $this->assign('investment_list',GamblerKingInvestmentUser::alias('a')->field('a.*,i.name')->join('__GAMBLER_KING_INVESTMENT__ i','a.investment_id=i.id')->where(['a.state'=>1,'a.king_id'=>$info['king_id']])->select());
        switch ($info['type']){
            case 1:
            case 2:
            case 4:
                return $this->fetch('user_action_edit');
                break;
            case 3:
                return $this->fetch('user_action_edit1');
                break;

        }
    }
    
    /**
     * Action添加与编辑通用方法
     */
    public function ActionCommon()
    {

        IS_POST && $this->jump($this->logicAction->ActionEdit($_POST));
        

    }
    /**
     * Action执行方法
     */
    public function implement()
    {

        $this->jump($this->logicAction->implement($this->param));


    }

    /**
     * Action分类添加
     */
    public function ActionCategoryAdd()
    {
        
        IS_POST && $this->jump($this->logicAction->ActionCategoryEdit($this->param));
        
        return $this->fetch('Action_category_edit');
    }
    
    /**
     * Action分类编辑
     */
    public function ActionCategoryEdit()
    {
        
        IS_POST && $this->jump($this->logicAction->ActionCategoryEdit($this->param));
        
        $info = $this->logicAction->getActionCategoryInfo(['id' => $this->param['id']]);
        
        $this->assign('info', $info);
        
        return $this->fetch('Action_category_edit');
    }
    
    /**
     * Action分类列表
     */
    public function ActionCategoryList()
    {
        
        $this->assign('list', $this->logicAction->getActionCategoryList());
       
        return $this->fetch('Action_category_list');
    }
    
    /**
     * Action分类删除
     */
    public function ActionCategoryDel($id = 0)
    {
        
        $this->jump($this->logicAction->ActionCategoryDel(['id' => $id]));
    }
    
    /**
     * 数据状态设置
     */
    public function setStatus()
    {
        
        $this->jump($this->logicAdminBase->setStatus('GamblerKingAction', $this->param));
    }
}
